<?php

/**
 * Menu(菜单管理)
 * Some rights reserved：abc3210.com
 * Contact email:admin@abc3210.com
 */
class MenuAction extends AdminbaseAction {

    protected $Menu;

    function _initialize() {
        parent::_initialize();
        $this->Menu = D("Menu");
        $this->assign("Menucache", $this->Cache['Menu']);
    }

    /**
     *  显示菜单
     */
    public function index() {
        $result = F("Menu");
        if (!$result) {
            $this->Menu->Menucache();
        }
        $this->assign("Menu", $result);
        $this->display();
    }

    /**
     * 显示菜单导航
     */
    public function public_current_pos() {
        $parentid = $this->_get("parentid");
        import('@.ORG.Util.Tree');
        $Tree = new Tree();
        $data = array();
        $Tree->arr = $this->Cache['eMenu'];
        $categorys = $Tree->get_pos($parentid);
        foreach($categorys as $k=>$v){
            $html[] = $v['name'];
        }
        echo implode(">", $html);
    }

    /**
     *  添加
     */
    public function add() {
        $this->display();
    }
    
    /**
     *  删除
     */
    public function delete() {
        $count = $this->Menu->where(array("parentid" => (int) $_GET['id']))->count();
        if ($count > 0) {
            $this->error("该菜单下还有子菜单，无法删除！");
        }
        $staus = parent::delete($this->Menu);
        if ($staus) {
            //更新缓存
            $this->Menu->Menucache();
            $this->success("删除菜单成功！");
        } else {
            $this->error($this->Menu->getError());
        }
    }

    /**
     *  编辑
     */
    public function edit() {
        $id = (int) $_GET['id'];
        $pk = ucfirst($this->Menu->getPk()); //取得主键
        $do = 'getBy' . $pk;
        $vo = $this->Menu->$do($id); //TP 5.3.12
        //参数处理
        $vo['data'] = $this->Menu->ArrayDataMenu($this->Menu->Data_unserialize($vo['data']));
        $this->assign('Menudata', $vo);
        $this->display();
    }

    /**
     *  更新
     */
    public function updata() {
        $status = parent::updata($this->Menu);
        if ($status) {
            //更新缓存
            $this->Menu->Menucache();
            $this->assign("jumpUrl", U('Menu/index'));
            $this->success("更新成功！");
        } else {
            $this->error($this->Menu->getError());
        }
    }

    /**
     *  添加菜单
     */
    public function insert() {
        $status = parent::insert($this->Menu);
        if ($status) {
            //更新缓存
            $this->Menu->Menucache();
            $this->success("添加成功！");
        } else {
            $this->error($this->Menu->getError());
        }
    }

    public function listorders() {
        $status = parent::listorders($this->Menu);
        if ($status) {
            $this->Menu->Menucache();
            $this->success("排序更新成功！");
        } else {
            $this->error("排序更新失败！");
        }
    }

}

?>